home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 109 / EnigmaAmiga109CD.iso / dalla rivista / host contacted / jikes.lha / jikes-1.11 / src / jcl / jcl_class.h < prev    next >
C/C++ Source or Header  |  1999-11-04  |  24KB  |  728 lines

  1. // $Id: jcl_class.h,v 1.1 1999/11/04 18:48:03 shields Exp $
  2. //
  3. // This software is subject to the terms of the IBM Jikes Compiler
  4. // License Agreement available at the following URL:
  5. // http://www.ibm.com/research/jikes.
  6. // Copyright (C) 1996, 1998, International Business Machines Corporation
  7. // and others.  All Rights Reserved.
  8. // You must accept the terms of that agreement to use this software.
  9. //
  10. #ifndef jcl_class_INCLUDED
  11. #define jcl_class_INCLUDED
  12.  
  13. #include <stdio.h>
  14. #include "jcl_access.h"
  15. #include "jcl_dynamic.h"
  16. #include "jcl_unicode.h"
  17.  
  18.  
  19. class cp_info
  20. {
  21. public:
  22.     u1 tag;
  23.  
  24.     cp_info(u1 _tag) : tag(_tag) {}
  25.  
  26.     virtual ~cp_info() {}
  27. #ifdef TEST
  28.     virtual void print(DynamicArray<cp_info *>& constant_pool) {
  29.             cout << (int) tag;
  30.     }
  31.     virtual void describe(DynamicArray<cp_info *>& constant_pool) {
  32.             cout << (int) tag;
  33.     }
  34. #endif
  35. };
  36.  
  37.  
  38. class CONSTANT_Class_info : public cp_info
  39. {
  40. public:
  41.     /* u1 tag; */
  42.     u2 name_index;
  43.  
  44.     CONSTANT_Class_info(u1 _tag) : cp_info(_tag) {}
  45.     virtual ~CONSTANT_Class_info() { }
  46. #ifdef TEST
  47.         virtual void print(DynamicArray<cp_info *>& constant_pool) {
  48.                 cout << "CONSTANT_Class_info: name_index " << name_index << "\n";
  49.         }
  50.         virtual void describe(DynamicArray<cp_info *>& constant_pool) {
  51.                 cout << "Class:";  constant_pool[name_index]->describe(constant_pool);
  52.         }
  53. #endif  
  54. };
  55.  
  56.  
  57.  
  58.  
  59. class CONSTANT_Fieldref_info : public cp_info
  60. {
  61. public:
  62.     /* u1 tag; */
  63.     u2 class_index;
  64.     u2 name_and_type_index;
  65.  
  66.     CONSTANT_Fieldref_info(u1 _tag) : cp_info(_tag) {}
  67.     virtual ~CONSTANT_Fieldref_info() {}
  68. #ifdef TEST
  69.         virtual void print(DynamicArray<cp_info *>& constant_pool) {
  70.                 cout << "CONSTANT_Fieldref_info: class_index: " << class_index
  71.                          << ", name_and_type_index: " << name_and_type_index << "\n";
  72.         }
  73.         virtual void describe(DynamicArray<cp_info *>& constant_pool) {
  74.                 constant_pool[class_index]->describe(constant_pool); cout << ".";
  75.                 constant_pool[name_and_type_index]->describe(constant_pool);
  76.         }
  77. #endif  
  78. };
  79.  
  80.  
  81. class CONSTANT_Methodref_info : public cp_info
  82. {
  83. public:
  84.     /* u1 tag; */
  85.     u2 class_index;
  86.     u2 name_and_type_index;
  87.  
  88.  
  89.     CONSTANT_Methodref_info(u1 _tag) : cp_info(_tag) {}
  90.     virtual ~CONSTANT_Methodref_info() {}
  91. #ifdef TEST
  92.         virtual void print(DynamicArray<cp_info *>& constant_pool) {
  93.                 cout << "CONSTANT_Methodref_info: class_index: " << class_index
  94.                          << ", name_and_type_index: " << name_and_type_index << "\n";
  95.         }
  96.         virtual void describe(DynamicArray<cp_info *>& constant_pool) {
  97.                 constant_pool[class_index]->describe(constant_pool); cout << ".";
  98.                 constant_pool[name_and_type_index]->describe(constant_pool);
  99.         }
  100. #endif  
  101. };
  102.  
  103.  
  104. class CONSTANT_InterfaceMethodref_info : public cp_info
  105. {
  106. public:
  107.     /* u1 tag; */
  108.     u2 class_index;
  109.     u2 name_and_type_index;
  110.  
  111.     CONSTANT_InterfaceMethodref_info(u1 _tag) : cp_info(_tag) {}
  112.     virtual ~CONSTANT_InterfaceMethodref_info() {}
  113. #ifdef TEST
  114.         virtual void print(DynamicArray<cp_info *>& constant_pool) {
  115.                 cout << "CONSTANT_InterfaceMethodref_info: class_index: " << class_index
  116.                          << ", name_and_type_index: " << name_and_type_index << "\n";
  117.         }
  118.         virtual void describe(DynamicArray<cp_info *>& constant_pool) {
  119.                 constant_pool[class_index]->describe(constant_pool); cout << ".";
  120.                 constant_pool[name_and_type_index]->describe(constant_pool);
  121.         }
  122. #endif  
  123. };
  124.  
  125.  
  126. class CONSTANT_String_info : public cp_info
  127. {
  128. public:
  129.     /* u1 tag; */
  130.     u2 string_index;
  131.  
  132.     CONSTANT_String_info(u1 _tag) : cp_info(_tag) {}
  133.     virtual ~CONSTANT_String_info() {}
  134. #ifdef TEST
  135.         virtual void print(DynamicArray<cp_info *>& constant_pool) {
  136.                 cout << "CONSTANT_String_info: string_index: " << string_index << "\n";
  137.         }
  138.         virtual void describe(DynamicArray<cp_info *>& constant_pool) {
  139.                 constant_pool[string_index]->describe(constant_pool);
  140.         }
  141. #endif
  142. };
  143.  
  144.  
  145. class CONSTANT_Integer_info : public cp_info
  146. {
  147. public:
  148.     /* u1 tag; */
  149.     u4 bytes;
  150.  
  151.     CONSTANT_Integer_info(u1 _tag) : cp_info(_tag) {}
  152.     virtual ~CONSTANT_Integer_info() {}
  153. #ifdef TEST
  154.         virtual void print(DynamicArray<cp_info *>& constant_pool) {
  155.         int val;
  156.         val = ((bytes>>24)&0xff)<<24 | ((bytes>>16)&0xff)<<16
  157.                 | ((bytes>>8)&0xff)<<8 | (bytes&0xff);
  158. //              cout << "CONSTANT_Integer_info: bytes " <<  value << "\n";
  159.                 cout << "CONSTANT_Integer_info: bytes " << val << "\n";
  160.         }
  161.         virtual void describe(DynamicArray<cp_info *>& constant_pool) {
  162.                 cout << "I:";
  163. //              constant_pool[string_index]->describe(constant_pool);
  164.         }
  165. #endif  
  166. };
  167.  
  168.  
  169. class CONSTANT_Float_info : public cp_info
  170. {
  171. public:
  172.     /* u1 tag; */
  173.     u4 bytes;
  174.  
  175.     CONSTANT_Float_info(u1 _tag) : cp_info(_tag) {}
  176.     virtual ~CONSTANT_Float_info() {}
  177. #ifdef TEST
  178.         virtual void print(DynamicArray<cp_info *>& constant_pool) {
  179.                 cout << "CONSTANT_Float_info: bytes " << (float) bytes << "\n";
  180.         }
  181.         virtual void describe(DynamicArray<cp_info *>& constant_pool) {
  182.                 cout << "F:";
  183. //              constant_pool[string_index]->describe(constant_pool);
  184.         }
  185. #endif  
  186. };
  187.  
  188.  
  189. class CONSTANT_Long_info : public cp_info
  190. {
  191. public:
  192.     /* u1 tag; */
  193.     u4 high_bytes;
  194.     u4 low_bytes;
  195.  
  196.     CONSTANT_Long_info(u1 _tag) : cp_info(_tag) {}
  197.     virtual ~CONSTANT_Long_info() {}
  198. #ifdef TEST
  199.         virtual void print(DynamicArray<cp_info *>& constant_pool) {
  200.                 cout << "CONSTANT_Long_info: bytes \n";
  201.         }
  202.         virtual void describe(DynamicArray<cp_info *>& constant_pool) {
  203.                 cout << "L:";
  204. //              constant_pool[string_index]->describe(constant_pool);
  205.         }
  206. #endif  
  207. };
  208.  
  209.  
  210. class CONSTANT_Double_info : public cp_info
  211. {
  212. public:
  213.     /* u1 tag; */
  214.     u4 high_bytes;
  215.     u4 low_bytes;
  216.  
  217.     CONSTANT_Double_info(u1 _tag) : cp_info(_tag) {}
  218.     virtual ~CONSTANT_Double_info() {}
  219. #ifdef TEST
  220.         virtual void print(DynamicArray<cp_info *>& constant_pool) {
  221.                 cout << "CONSTANT_Float_info: bytes  \n";
  222.         }
  223.         virtual void describe(DynamicArray<cp_info *>& constant_pool) {
  224.                 cout << "D:";
  225. //              constant_pool[string_index]->describe(constant_pool);
  226.         }
  227. #endif  
  228. };
  229. class CONSTANT_NameAndType_info : public cp_info
  230. {
  231. public:
  232.     /* u1 tag; */
  233.     u2 name_index;
  234.     u2 descriptor_index;
  235.  
  236.     CONSTANT_NameAndType_info(u1 _tag) : cp_info(_tag) {}
  237.     virtual ~CONSTANT_NameAndType_info() {}
  238. #ifdef TEST
  239.         virtual void print(DynamicArray<cp_info *>& constant_pool) {
  240.                 cout << "CONSTANT_NameAndType_info: name_index: " << name_index
  241.                          << ", descriptor_index: " << descriptor_index << "\n";
  242.         }
  243.         virtual void describe(DynamicArray<cp_info *>& constant_pool) {
  244.                 constant_pool[name_index]->describe(constant_pool);
  245.                 cout << " ";
  246.                 constant_pool[descriptor_index]->describe(constant_pool);
  247.         }
  248. #endif  
  249. };
  250.  
  251. class CONSTANT_Utf8_info : public cp_info
  252. {
  253. public:
  254.     /* u1 tag; */
  255.     u2 length() { return length_; }
  256.     char *bytes; /* bytes[length+1] ... after input a '\0' will be added. */
  257.  
  258.     CONSTANT_Utf8_info(u1 _tag) : cp_info(_tag) {}
  259.  
  260.     virtual ~CONSTANT_Utf8_info()
  261.     {
  262.         delete [] bytes;
  263.     }
  264. public:
  265.     u2 length_;
  266. #ifdef TEST
  267.         virtual void print(DynamicArray<cp_info *>& constant_pool) {
  268.                 
  269.                 cout << "CONSTANT_Utf8_info: length: " << length_<< " ";
  270.                 for (int i=0;i<length_;i++) Unicode::Cout(bytes[i]);
  271.                 cout << "\n";
  272.                 // should only do packing when actually write the string out!!
  273.                 // so have same common internal form on input and output.
  274.         }
  275.         virtual void describe(DynamicArray<cp_info *>& constant_pool) {
  276.                 
  277.                 cout << "\"";
  278.                 for (int i=0;i<length_;i++) Unicode::Cout(bytes[i]);
  279.                 cout << "\"";
  280. //              Unicode::Cout(bytes);
  281.         }
  282. #endif  
  283. };
  284.  
  285. // field_info and method_infoshould be defined here, but they contain attributes, so it is necessary
  286. // to define the attributes first.
  287.  
  288.  
  289. class attribute_info
  290. {
  291. public:
  292.     enum 
  293.     {
  294.         Generic,
  295.         SourceFile,
  296.         ConstantValue,
  297.         Code,
  298.         Exceptions,
  299.         LineNumberTable,
  300.         LocalVariableTable,
  301.         Synthetic,
  302.         Deprecated,
  303.         InnerClasses
  304.     };
  305.  
  306.     u1 tag;
  307.     u2 attribute_name_index;
  308.     u4 attribute_length;
  309.  
  310.     attribute_info(u1 _tag) : tag(_tag) {}
  311.         attribute_info(u1 _tag, u2 _name_index, u4 _length) :
  312.                         tag(_tag), attribute_name_index(_name_index),
  313.                         attribute_length(_length) {}
  314.  
  315.     virtual ~attribute_info() {};
  316. #ifdef TEST
  317.         virtual void print(DynamicArray<cp_info *>& constant_pool) {
  318.                 cout << "print for attribute info tag " << tag << " not defined\n";
  319.         }
  320. #endif  
  321. };
  322.  
  323. class GenericAttribute_info : public attribute_info
  324. {
  325. public:
  326. //    u2 attribute_name_index;
  327.     u4 attribute_length() { return info.length(); }
  328.     DynamicArray<u1> info; /* info[attribute_length] */
  329.  
  330.     GenericAttribute_info(u2 &_name_index, u4 &_length)
  331.            : attribute_info(Generic, _name_index, _length) {}
  332.  
  333.     virtual ~GenericAttribute_info() { }
  334. #ifdef TEST
  335.         virtual void print(DynamicArray<cp_info *>& constant_pool) {
  336.                 cout << "print for attribute info tag " << tag << " not defined\n";
  337.         }
  338. #endif  
  339. };
  340.  
  341. class SourceFile_attribute : public attribute_info
  342. {
  343. public:
  344. //    u2 attribute_name_index;
  345. //    u4 attribute_length; /* must be 2 */
  346.     u2 sourcefile_index;
  347.  
  348.     SourceFile_attribute(u2 &_name_index, u4 &_length)
  349.           : attribute_info(SourceFile,_name_index,_length) {}
  350.  
  351.     virtual ~SourceFile_attribute() {}
  352. #ifdef TEST
  353.         virtual void print(DynamicArray<cp_info *>& constant_pool) {
  354.                 cout << "SourceFile_attribute attribute_name_index " << attribute_name_index
  355.                          << " length " << attribute_length
  356.                          << " sourcefile_index " << sourcefile_index << "\n";
  357.         }
  358. #endif  
  359. };
  360.  
  361. class ConstantValue_attribute : public attribute_info
  362. {
  363. public:
  364.     ConstantValue_attribute(u2 &_name_index, u4 &_length)
  365.             : attribute_info(ConstantValue,_name_index,_length) {}
  366.  
  367. //    u2 attribute_name_index;
  368. //    u4 attribute_length; /* must be 2 */
  369.     u2 constantvalue_index;
  370.  
  371.     virtual ~ConstantValue_attribute() {}
  372. #ifdef TEST
  373.         virtual void print(DynamicArray<cp_info *>& constant_pool) {
  374.                 cout << "ConstantValue_attribute attribute_name_index " << attribute_name_index
  375.                          << " attribute_length " << attribute_length
  376.                          << " constantvalue_index " << constantvalue_index << "\n";
  377.         }
  378. #endif  
  379. };
  380.  
  381. class Code_attribute : public attribute_info
  382. {
  383. public:
  384.     Code_attribute(u2 &_name_index, u4 &_length)
  385.          : attribute_info(Code,_name_index,_length){}
  386.  
  387. //    u2 attribute_name_index;
  388. //    u4 attribute_length;
  389.     u2 max_stack;
  390.     u2 max_locals;
  391.     /* u4 code_length; */
  392.     DynamicArray<u1> code; /* code[code_length] */
  393.     u2 exception_table_length() { return exception_table.length(); }
  394.     struct exception_element
  395.     {
  396.         u2 start_pc;
  397.         u2 end_pc;
  398.         u2 handler_pc;
  399.         u2 catch_type;
  400.     };
  401.     DynamicArray<exception_element> exception_table; /* exceptiontable[exception_table_length] */
  402.     u2 attributes_count() { return attributes.length(); }
  403.     DynamicArray<attribute_info *> attributes; /* attributes[attributes_count] */
  404.         Code_attribute() : attribute_info(Code,0,0),
  405.     max_stack(0),max_locals(0)
  406.                         {}
  407.     virtual ~Code_attribute()
  408.      {
  409.          for (int i = 0; i < attributes.length(); i++)
  410.              if (attributes[i])
  411.                  delete attributes[i];
  412.      }
  413. #ifdef TEST     
  414. virtual void  print(DynamicArray<cp_info *>& constant_pool)
  415.         {
  416.  
  417.     void  opdmp(DynamicArray<cp_info *>& constant_pool, DynamicArray<u1>& code);
  418.                 int i;
  419.                 cout << "Code_attribute attribute_name_index " << attribute_name_index
  420.                          << " attribute_length " << attribute_length << "\n";
  421.                 cout << " max_stack " << max_stack <<
  422.                         " max_locals "  << max_locals <<
  423.                         " code_length "  << code.length() << "\n";
  424.                 if (exception_table.length()) {
  425.                         cout << " exception_table: " << exception_table.length() << " entries\n";
  426.                         for (i=0; i<exception_table.length(); i++) {
  427.                                 cout <<
  428.                                 "  start_pc " << exception_table[i].start_pc <<
  429.                                 "  end_pc " << exception_table[i].end_pc <<
  430.                                 "  handler_pc " << exception_table[i].handler_pc <<
  431.                                 "  catch_type " << exception_table[i].catch_type << "\n";
  432. //                              const_string(cp,exception_table[i].catch_type);
  433.                         }
  434.                 }
  435.                 opdmp(constant_pool,code);
  436.                 cout << "  \n";
  437.                 for (i=0;i<attributes.length();i++) {
  438.                         attributes[i]->print(constant_pool);
  439.                 }
  440.         }
  441. #endif  
  442.  
  443. };
  444.  
  445. class Exceptions_attribute : public attribute_info
  446. {
  447. public:
  448. //    u2 attribute_name_index;
  449. //    u4 attribute_length; /* must be 2 */
  450.      u2 number_of_exceptions() { return exception_index_table.length(); }
  451.     DynamicArray<u2> exception_index_table; /* exception_index_table[number_of_exceptions] */
  452.  
  453.     Exceptions_attribute(u2 &_name_index, u4 &_length)
  454.               : attribute_info(Exceptions,_name_index, _length) {}
  455.      virtual ~Exceptions_attribute() { }
  456. #ifdef TEST
  457.         virtual void print(DynamicArray<cp_info *>& constant_pool) {
  458.                 cout << "Exceptions_attribute attribute_name_index " << attribute_name_index
  459.                          << " attribute_length " << attribute_length << "\n";
  460.                 for (int i=0; i<exception_index_table.length(); i++) {
  461.                         cout << "    " << exception_index_table[i];
  462.                 }
  463.                 cout << "\n";
  464.         }
  465. #endif  
  466. };
  467.  
  468. class LineNumberTable_attribute : public attribute_info
  469. {
  470. public:
  471.     LineNumberTable_attribute(u2 &_name_index, u4 &_length)
  472.                    : attribute_info(LineNumberTable,_name_index,_length) {}
  473.  
  474. //    u2 attribute_name_index;
  475. //    u4 attribute_length;
  476.      u2 line_number_table_length() { return line_number_table.length();}
  477.     struct line_number_element
  478.     {
  479.         u2 start_pc;
  480.         u2 line_number;
  481.     };
  482.     DynamicArray<line_number_element> line_number_table; /* line_number_table[line_number_table_length] */
  483.  
  484.     virtual ~LineNumberTable_attribute() { }
  485. #ifdef TEST
  486.         virtual void print(DynamicArray<cp_info *>& constant_pool) {
  487.                 cout << "LineNumberTable_attribute attribute_name_index " << attribute_name_index
  488.                          << " attribute_length " << attribute_length << "\n";
  489.                 cout << " line_number_table_length " << line_number_table.length() <<"\n";
  490.                 for (int i=0; i<line_number_table.length(); i++) {
  491.                         cout << "     " << i << "  start_pc " << line_number_table[i].start_pc
  492.                                         << "  line_number " << line_number_table[i].line_number << "\n";
  493.                 }
  494.         }
  495. #endif  
  496. };
  497.  
  498.  
  499. class LocalVariableTable_attribute : public attribute_info
  500. {
  501. public:
  502.     LocalVariableTable_attribute(u2 &_name_index, u4 &_length)
  503.                  : attribute_info(LocalVariableTable,_name_index,_length){}
  504.  
  505. //    u2 attribute_name_index;
  506. //    u4 attribute_length;
  507.      u2 local_variable_table_length() { return local_variable_table.length();}
  508.     struct local_variable_element
  509.     {
  510.         u2 start_pc;
  511.         u2 length;
  512.         u2 name_index;
  513.         u2 descriptor_index;
  514.         u2 index;
  515.     };
  516.     DynamicArray<local_variable_element> local_variable_table; /* local_variable_table[local_variable_table_length] */
  517.  
  518.     virtual ~LocalVariableTable_attribute() { }
  519. #ifdef TEST
  520.         virtual void print(DynamicArray<cp_info *>& constant_pool) {
  521.                 cout << "LocalVariableTable_attribute attribute_name_index " << attribute_name_index
  522.                          << " attribute_length " << attribute_length << "\n";
  523.                 cout << " local_variable_table_length " << local_variable_table.length() <<"\n";
  524.                 for (int i=0; i<local_variable_table.length(); i++) {
  525.                         cout << "     " << i << "  start_pc " << local_variable_table[i].start_pc
  526.                                  << "  length " << local_variable_table[i].length
  527.                                  << "  name_index " << local_variable_table[i].name_index
  528.                                  << "  descriptor_index " << local_variable_table[i].descriptor_index
  529.                                  << "  index " << local_variable_table[i].index << "\n";
  530.                 }
  531.         }
  532. #endif  
  533. };
  534.  
  535. class InnerClasses_attribute : public attribute_info
  536. {
  537. public:
  538.     InnerClasses_attribute(u2 &_name_index, u4 &_length)
  539.                  : attribute_info(InnerClasses,_name_index,_length){}
  540.  
  541. //    u2 attribute_name_index;
  542. //    u4 attribute_length;
  543.       u2 number_of_classes;
  544.      u2 inner_classes_length() { return inner_classes.length();}
  545.     struct local_variable_element
  546.     {
  547.         u2 inner_class_info_index;
  548.         u2 outer_class_info_index;
  549.         u2 inner_name_index;
  550.         u2 inner_class_access_flags;
  551.     };
  552.     DynamicArray<local_variable_element> inner_classes; /* inner_classes[inner_classes_length] */
  553.  
  554.     virtual ~InnerClasses_attribute() { }
  555. #ifdef TEST
  556.         virtual void print(DynamicArray<cp_info *>& constant_pool) {
  557.                 cout << "InnerClasses_attribute attribute_name_index " << attribute_name_index
  558.                          << " attribute_length " << attribute_length << "\n";
  559.                 cout << " inner_classes_length " << inner_classes.length() <<"\n";
  560.                 for (int i=0; i<inner_classes.length(); i++) {
  561.                         cout << "     " << i << "  inner_class_info_index " << inner_classes[i].inner_class_info_index
  562.                                  << "  outer_class_info_index " << inner_classes[i].outer_class_info_index
  563.                                  << "  inner_name_index " << inner_classes[i].inner_name_index
  564.                                  << "  inner_class_access_flags " << inner_classes[i].inner_class_access_flags
  565.                                  << "\n";
  566.                 }
  567.         }
  568. #endif  
  569. };
  570.  
  571. class Synthetic_attribute : public attribute_info
  572. {
  573. public:
  574.     Synthetic_attribute(u2 &_name_index, u4 &_length)
  575.                  : attribute_info(Synthetic,_name_index,_length){}
  576.  
  577. //    u2 attribute_name_index;
  578. //    u4 attribute_length;
  579.  
  580.     virtual ~Synthetic_attribute() { }
  581. #ifdef TEST
  582.         virtual void print(DynamicArray<cp_info *>& constant_pool) {
  583.                 cout << "Synthetic_attribute attribute_name_index " << attribute_name_index
  584.                          << " attribute_length " << attribute_length << "\n";
  585.         }
  586. #endif  
  587. };
  588.  
  589. class Deprecated_attribute : public attribute_info
  590. {
  591. public:
  592.     Deprecated_attribute(u2 &_name_index, u4 &_length)
  593.                  : attribute_info(Deprecated, _name_index,_length){}
  594.  
  595. //    u2 attribute_name_index;
  596. //    u4 attribute_length;
  597.  
  598.     virtual ~Deprecated_attribute() { }
  599. #ifdef TEST
  600.         virtual void print(DynamicArray<cp_info *>& constant_pool) {
  601.                 cout << "Deprecated_attribute attribute_name_index " << attribute_name_index
  602.                          << " attribute_length " << attribute_length << "\n";
  603.         }
  604. #endif  
  605. };
  606.  
  607. class field_info : public AccessFlags
  608. {
  609. public:
  610.     /* u2 access_flags; */
  611.     u2 name_index;
  612.     u2 descriptor_index;
  613.      u2 attributes_count() { return attributes.length();}
  614.     DynamicArray<attribute_info *> attributes; /* attributes[attributes_count] */
  615.  
  616.     virtual ~field_info()
  617.      {
  618.          for (int i = 0; i < attributes.length(); i++)
  619.              if (attributes[i])
  620.                  delete attributes[i];
  621.      }
  622. #ifdef TEST
  623.         virtual void print(DynamicArray<cp_info *>& constant_pool) {
  624.                 cout << "field_info  name_index " << name_index
  625.                          << "  descriptor_index " << descriptor_index << "\n";
  626.                 AccessFlags::print();
  627.                 for (int i=0; i<attributes.length(); i++) {
  628.                         attributes[i]->print(constant_pool);
  629.                 }
  630.                 cout << "\n";
  631.         }
  632. #endif  
  633. };
  634.  
  635.  
  636. class method_info : public AccessFlags
  637. {
  638. public:
  639.     /* u2 access_flags; */
  640.     u2 name_index;
  641.     u2 descriptor_index;
  642.      u2 attributes_count() { return attributes.length(); }
  643.     DynamicArray<attribute_info *> attributes; /* attributes[attributes_count] */
  644.  
  645.         // shouldn't have to access ast to define class.h
  646.         //      initialize_method_info(Ast_MethodDeclaration *p);
  647.     method_info(u2 & _access_flags, u2 & _name_index, u2 & _descriptor_index)
  648.                  : AccessFlags(_access_flags),
  649.                                    name_index(_name_index),
  650.                                    descriptor_index(_descriptor_index) {}
  651.  
  652.         method_info() : AccessFlags(), name_index(0), descriptor_index(0) {}
  653.     virtual ~method_info()
  654.      {
  655.          for (int i = 0; i < attributes.length(); i++)
  656.              if (attributes[i])
  657.                  delete attributes[i];
  658.      }
  659. #ifdef TEST
  660.         virtual void print(DynamicArray<cp_info *>& constant_pool) {
  661.                 cout << "method_info  name_index " << name_index
  662.                          << "  descriptor_index " << descriptor_index << "\n";
  663.                 AccessFlags::print();
  664.                 for (int i=0; i<attributes.length(); i++) {
  665.                         attributes[i]->print(constant_pool);
  666.                 }
  667.                 cout << "\n";
  668.         }
  669. #endif  
  670. };
  671.  
  672.  
  673.  
  674.  
  675. class ClassFile : public AccessFlags
  676. {
  677. private:
  678. public:
  679.     enum 
  680.     {
  681.         CONSTANT_Class              = 7,
  682.         CONSTANT_Fieldref           = 9,
  683.         CONSTANT_Methodref          = 10,
  684.         CONSTANT_InterfaceMethodref = 11,
  685.         CONSTANT_String             = 8,
  686.         CONSTANT_Integer            = 3,
  687.         CONSTANT_Float              = 4,
  688.         CONSTANT_Long               = 5,
  689.         CONSTANT_Double             = 6,
  690.         CONSTANT_NameAndType        = 12,
  691.         CONSTANT_Utf8               = 1
  692.     };
  693.  
  694.     u4 magic;
  695.     u2 minor_version;
  696.     u2 major_version;
  697.     u2 constant_pool_count() { return constant_pool.length(); }
  698.     DynamicArray<cp_info *> constant_pool; /* cp_info[constant_pool_count] */
  699. /*    u2 access_flags; */
  700.     u2 this_class;
  701.     u2 super_class;
  702.     u2 interfaces_count() { return interfaces.length(); }
  703.     DynamicArray<u2> interfaces; /* interfaces[interfaces_count] */
  704.     u2 fields_count() { return fields.length(); }
  705.     DynamicArray<field_info> fields; /* fields[fields_count] */
  706.     u2 methods_count() { return methods.length();}
  707.     DynamicArray<method_info> methods; /* methods[methods_count] */
  708.     u2 attributes_count() { return attributes.length(); }
  709.     DynamicArray<attribute_info *> attributes; /* attributes[attributes_count] */
  710.  
  711.         virtual void reset(){           // reset to empty state.
  712.                 constant_pool.reset();
  713.                 fields.reset();
  714.                 methods.reset();
  715.                 attributes.reset();
  716.                 this_class = super_class = 0;
  717.         }
  718.  
  719. public:
  720.     ~ClassFile(){}; 
  721. #ifdef TEST
  722.     virtual void print();
  723.     virtual void print_const(DynamicArray<cp_info *>& constant_pool,int i);
  724.     virtual void print_const(int i);
  725. #endif                          
  726. };
  727. #endif
  728.